package Servlet.TeacherServlet;

import Entity.Teacher;
import Service.TeacherService.TeacherService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/*
负责教师 注册 数据接口
 */
@WebServlet(value = "/teacherRegister")
public class TeacherRegister extends HttpServlet {

    private TeacherService teacherService = new TeacherService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");

        System.out.println(123);


        String teacherId= request.getParameter("teacherId");
        String teacherPassword= request.getParameter("teacherPassword");
        String teacherName= request.getParameter("teacherName");
        String teacherGrade= request.getParameter("teacherGrade");
        String teacherType= request.getParameter("teacherType");
        String department= request.getParameter("department");

       // System.out.println("teacherId:"+teacherId);

        Teacher teacher = new Teacher();
        teacher.setTeacherId(teacherId);
        teacher.setTeacherPassword(teacherPassword);
        teacher.setTeacherName(teacherName);
        teacher.setTeacherGrade(teacherGrade);
        teacher.setTeacherType(teacherType);
        teacher.setDepartment(department);


        PrintWriter out = response.getWriter();

        int status = teacherService.teacherRegister(teacher);
        out.print(status);

        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
